package com.oa.official.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.oa.official.common.utils.LoginUserInfoHelper;
import com.oa.official.entity.process.ProcessRecord;
import com.oa.official.entity.system.SysUser;
import com.oa.official.mapper.OaProcessRecordMapper;
import com.oa.official.mapper.SysUserMapper;
import com.oa.official.service.OaProcessRecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 审批记录 服务实现类
 * </p>
 *
 * @author atguigu
 * @since 2023-02-15
 */
@Service
public class OaProcessRecordServiceImpl extends ServiceImpl<OaProcessRecordMapper, ProcessRecord> implements OaProcessRecordService {

    @Resource
    private SysUserMapper sysUserMapper;

    /**
     * 记录操作审批信息记录
     * @param processId
     * @param status
     * @param description
     */
    @Override
    public void record(Long processId, Integer status, String description) {
        Long userId = LoginUserInfoHelper.getUserId();
        SysUser sysUser = sysUserMapper.selectById(userId);
        ProcessRecord processRecord = new ProcessRecord();
        //审批流程id
        processRecord.setProcessId(processId);
        processRecord.setStatus(status);
        processRecord.setDescription(description);
        //操作用户id
        processRecord.setOperateUser(sysUser.getName());
        //操作用户
        processRecord.setOperateUserId(userId);
        baseMapper.insert(processRecord);
    }
}
